package com.ktmall.ktmalluijava.service.impl;

import com.ktmall.ktmalluijava.mapper.AddressMapper;
import com.ktmall.ktmalluijava.pojo.Address;
import com.ktmall.ktmalluijava.service.AddressService;
import com.ktmall.ktmalluijava.utils.Page;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;


/**
 * @author ZhouShuang
 * @version 17
 * @Title
 * @date 2025/5/13 上午11:00
 */
@Service
public class AddressServiceImpl implements AddressService {
    @Resource
    private AddressMapper mapper;
    /**
     * 条件分页查询
     *
     * @param username
     * @param telName
     * @param telNumber
     * @param pageNo
     * @param pageSize
     * @return
     */
    @Override
    public Page<Address> select(String username, String telName, String telNumber, Integer pageNo, Integer pageSize) {
        Page<Address> addressPage = new Page<>();
        addressPage.setPageSize(pageSize);
        addressPage.setTotalCount(mapper.count(username,telName,telNumber));
        addressPage.setPageNo(pageNo);
        int offset = (addressPage.getPageNo()-1)*addressPage.getPageSize();
        addressPage.setData(mapper.select(username,telName,telNumber,addressPage.getPageSize(),offset));
        return addressPage;
    }

    /**
     * 逻辑删除
     *
     * @param id
     * @return
     */
    @Override
    public int delete(Integer... id) {
        if(id.length==1){
            return mapper.delete(id[0]);
        }
        int count = 0;
        for (Integer integer : id) {
            count += mapper.delete(integer);
        }
        return count;
    }
}
